package com.cy.config;

import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wxhn1
 */
@RestControllerAdvice
public class ShiroExceptionHandler {

    @ExceptionHandler(UnauthenticatedException.class)
    public Map<String,Object> ex1(UnauthenticatedException e){
        Map<String,Object> map = new HashMap<>();
        map.put("code","1001");
        map.put("msg","请先登录");
        return map;
    }

    @ExceptionHandler(UnauthorizedException.class)
    public Map<String,Object> ex1(UnauthorizedException e){
        Map<String,Object> map = new HashMap<>();
        map.put("code","1002");
        map.put("msg","您不具备访问权限");
        return map;
    }
}
